/** jsinfo for purchase_mag.jsp  **/
function doInspage(){
	document.all["operate"].value = "inspage";
	document.forms[0].submit();
}
//标记物料到货入库
function doLabel(id,obj){
	if(id!=""){
		comdwr.Stock_Label(id,function(lab){
			if(lab!=""){
				var td = obj.parentNode;
				td.innerHTML ="<span class='RoleSpan' onclick=\"doAgain('"+id+"')\" title='重订采购单' style='color: green;' onmouseout=\"doMsOut('green')\" onmouseover='doMsOver()'>重订采购单</span>";
				td.parentNode.childNodes[3].innerHTML = lab; //标记到货日期
			}else{
				_alert("标记物料到货入库失败！");
			}
		});
	}
}

function doPrint(){
	var oldaction = document.forms[0].action;
	document.forms[0].action = _c + "/docs/ys_stock/purchase_print.jsp";
	document.forms[0].submit();
	document.forms[0].action = oldaction;
}

function doDeltype(id){
	if(confirm("确定删除该采购单吗？")){
		document.all["pid"].value = id;
		document.all["operate"].value = "delinfo";
		document.forms[0].submit();
	}
}

function doUpdType(id){
	document.all["pid"].value = id;
	document.all["operate"].value = "updpage";
	document.forms[0].submit();
}
function doSelinfo(id){
	document.all["pid"].value = id;
	document.all["operate"].value = "selpage";
	document.forms[0].submit();
}
function doAgain(id){
	document.all["pid"].value = id;
	document.all["operate"].value = "againpage";
	document.forms[0].submit();
}
/** end  **/

/** jsinfo for purchase_ins.jsp  **/
//保存并查询
function doIns(){
	if(check()){
		if(confirm("确认保存信息?")){
			document.all.operate.value = "insinfo";
			document.forms[0].submit();
		}
	}
}
//限制添加快捷内容的字数  
var maxLength =30; 
function MaxInput(fo,len) {
	if(len!=""){
		maxLength=len;
	}
	if (fo.value.length > maxLength) {
		alert("输入内容过多！");
		fo.value = fo.value.substring(0, maxLength);
	}
}

//添加行功能
function addMak(obj) {
	var tr = obj["parentNode"]["parentNode"]["parentNode"];
	var tob = tr["parentNode"];
	var tab = tob["parentNode"];
	if(obj["value"] == "添加") {
		var tobs = tob["cloneNode"](1);
		var ntd = tobs["firstChild"]["firstChild"];
		ntd["childNodes"][1]["firstChild"]["value"] = "删除";
		//清空区域内input内容
		var ips = tobs.all.tags("INPUT");
		for (var i=0; i<ips.length; i++) {
			if(ips[i].name!=null&&ips[i].name!=""){
			  	ips[i].value = "";
			}
		}
		tab["appendChild"](tobs);
	} else {
		tab["removeChild"](tob);	
	}
}
//查询供应商信息
function doSelsupp(obj){
	if(obj.value!=""){
		//参数( 表名 , 查询列 , where列 , 空是自动生成语句不为空是用后台语句 ,true 表示文本框 false 表示下拉框 ) 
		//本次调用使用后台语句所以表名可以空
		comdwr.doSel_Info("ST01"," and supplierid ='"+obj.value+"'",function(map){
			document.all["supplyflag"].value = map.supplyflag;
			document.all["grade"].value  = map.grade;
			document.all["banknumber"].value = map.banknumber;
			document.all["bank"].value  = map.bank;
			document.all["bankname"].value = map.bankname;
			document.all["pur.linkman"].value = map.linkman;
			document.all["pur.telnumber"].value  = map.telnumber;
			document.all["pur.phone"].value  = map.phone;
		});
	}else{
		document.all["supplyflag"].value = "";
		document.all["grade"].value  = "";
		document.all["banknumber"].value = "";
		document.all["bank"].value  = "";
		document.all["bankname"].value = "";
		document.all["pur.linkman"].value = "";
		document.all["pur.telnumber"].value  = "";
		document.all["pur.phone"].value  = "";
	}
}
//查询物料信息
function doSelmak(obj){
	var tob = obj["parentNode"]["parentNode"]["parentNode"];
	if(obj.value!=""){
		comdwr.doSel_Info("ST02"," and goodsid ='"+obj.value+"'",function(map){
			tob.all["goodstype"].value = map.goodstype;
			tob.all["standard"].value  = map.standard;
			tob.all["brand"].value = map.brand;
			tob.all["unit"].value  = map.unit;
			tob.all["priceone"].value = map.price;
			tob.all["price"].value = map.price;
			tob.all["makingtype"].value = map.makingtype;
		});
	}else{
		tob.all["goodstype"].value = "";
		tob.all["standard"].value  = "";
		tob.all["brand"].value = "";
		tob.all["unit"].value  = "";
		tob.all["priceone"].value = "";
		tob.all["price"].value = "";
		tob.all["makingtype"].value = "";
	}
}

//计算总额
function doCount(tob,obj){
	var cgdj = tob.all["buyprice"];	//采购单价
	var cgsl = tob.all["buynum"];	//采购数量
	var cgze = tob.all["summoney"];	//总金额
	var hsdj = tob.all["price"];	//核算单价
	var hssl = tob.all["sumgoods"];	//核算数量
	var cgdw = tob.all["buyunit"];	//采购单位
	
	var zl = tob.all["goodstype"];//种类
	var gg = tob.all["standard"];	//规格
	var sl;
	if((doVprice(cgdj) && doVprice(cgsl)) || (doVprice(cgsl) && doVprice(cgze))){
		if(obj.name == "summoney"){
			cgdj.value = round((cgze.value-0)/(cgsl.value-0) ,2);
		}else{
			cgze.value = round((cgdj.value-0)*(cgsl.value-0) ,2);
		}
		//进行核算
		if(tob.all["makingtype"].value == "主料"){ //判断是否是主料
			if(cgdw.value =="吨"){
				var cs;
				if(zl.value.indexOf("正度")!=-1){
					cs = 2327;
				}else if(zl.value.indexOf("大度")!=-1){
					cs = 1884;
				}else{
					cs = 1;
				}
				hsdj.value = round((cgdj.value-0) / cs * (gg.value-0) / 500 ,2);
			}else if(cgdw.value =="领"){
				hsdj.value = round((cgdj.value-0) / 500 ,2);
			}else{
				hsdj.value = cgdj.value;
			}
			sl = round((cgze.value-0) / hsdj.value ,2);
		}else{
			hsdj.value = cgdj.value;
			sl = round((cgze.value-0) / hsdj.value ,2);
		}
		//不足1的按1算 求余
		if(sl%1!=0){
			sl = round((sl - (sl%1) + 1),2);
		}
		hssl.value = sl;
	}
}
function doObj(obj){
	var tob = obj["parentNode"]["parentNode"]["parentNode"];
	doCount(tob,obj);
}

//保存并查询
function doUpd(){
	if(check()){
		if(confirm("确认修改信息?")){
			document.all.operate.value = "updinfo";
			document.forms[0].submit();
		}
	}
}
function doback(){
	document.all.operate.value = "";
	document.forms[0].submit();
}